-- =============================================
-- Author:		<Le Dang Minh>
-- Create date: <24/01/2010>
-- Description:	<Create Insert TumeSheet record store procedure>
-- =============================================
--EXEC usp_Insert_Record_TimeSheet '5','2','2','2','2','01/23/2010','4','TEST'
USE TimeSheet
GO
IF EXISTS(SELECT * FROM sys.objects WHERE type = 'P' AND name = 'usp_Insert_Record_TimeSheet')
     DROP PROCEDURE usp_Insert_Record_TimeSheet
GO
CREATE PROCEDURE usp_Insert_Record_TimeSheet
	-- Add the parameters for the stored procedure here
	@UserId BIGINT,
	@ProjectId BIGINT,
	@ProductId INT,
	@ProcessId INT,
	@WorkId INT,
	@Date DATETIME,
	@Time FLOAT,
	@Description NTEXT
AS
BEGIN
	IF EXISTS(SELECT u.UserId FROM users u WHERE u.UserId=@UserId)
	BEGIN
		INSERT INTO ts_timesheet(UserId,ProjectId,ProductId,ProcessId,WorkId,Date,[Time],StatusId,[Description])
	    VALUES
	   (@UserId, @ProjectId, @ProductId, @ProcessId, @WorkId, @Date,@Time,3,@Description)
	END
	ELSE
		RAISERROR ('User is not exist!!',11,1)
	
END
GO

